/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package byblos.negocio.reserva;

import byblos.util.DataUtil;
import byblos.util.Periodo;
import java.io.Serializable;
import java.util.Calendar;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;

/**
 *
 * @author marano
 */
@Entity
@NamedQuery(name = "TemporadaPorPeriodo", query = "SELECT t FROM Temporada t WHERE " +
"?1 >= t.dataInicio AND ?1 <= t.dataTermino OR " +
"?2 >= t.dataInicio AND ?2 <= t.dataTermino OR " +
"?1 <= t.dataInicio AND ?2 >= t.dataTermino")
public class Temporada implements Serializable {

    @Id
    @GeneratedValue
    private int id;
    private String descricao;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Calendar dataInicio;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Calendar dataTermino;

    public Temporada() {
    }

    public int getQuantidadeDiasNaReserva(Reserva reserva) {
        return getPeriodo().getQuantidadeDiasIntersecao(reserva.getPeriodo());
    }

    public Periodo getPeriodo() {
        return new Periodo(dataInicio, dataTermino);
    }

    public Calendar getDataInicio() {
        return dataInicio;
    }

    public String getStringDataInicio() {
        return DataUtil.toString(dataInicio);
    }

    public void setDataInicio(Calendar dataInicio) {
        this.dataInicio = dataInicio;
    }

    public Calendar getDataTermino() {
        return dataTermino;
    }

    public String getStringDataTermino() {
        return DataUtil.toString(dataTermino);
    }

    public void setDataTermino(Calendar dataTermino) {
        this.dataTermino = dataTermino;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Temporada other = (Temporada) obj;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 97 * hash + this.id;
        return hash;
    }
}
